﻿using System;
using Csla.Xaml;
using HeThongThongTin.Library;
using System.ComponentModel;
using Utility;

namespace HeThongThongTin.UI.SL.DanhMuc.DM_Table
{
    public class DM_Table_ViewModel : ViewModel<HeThongThongTin.Library.DM_Table>
    {
        #region Event Declare
        public delegate void ChildList_AddedNew_EventHandler(object sender, ChildListAddedNewArgs e);
      
        public event ChildList_AddedNew_EventHandler ChildList_AddedNew;
        public event EventHandler LoadCompleted;
        #endregion

        #region Refresh Model
        public DM_Table_ViewModel()
        {
            BeginRefresh("NewDM_Table");
            
        }

        public DM_Table_ViewModel(int Khoa)
        {
            BeginRefresh("GetDM_Table", Khoa);
           
        }

        public void NewDM_TableViewModel()
        {
            BeginRefresh("NewDM_Table");
            
        }

        public void GetDM_TableViewModel(int Khoa)
        {
            BeginRefresh("GetDM_Table", Khoa);
        }

       
        public void SaveAndNew()
        {
            BeginSave();
            NewDM_TableViewModel();
        }
        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                Model.DM_Table_Fields.AddedNew += new EventHandler<Csla.Core.AddedNewEventArgs<DM_Table_FieldChild>>(DM_Table_Fields_AddedNew);
               
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }
        #endregion
        
        #region Add DM_Table Details Item
        public void AddDM_Table_FieldItem()
        {
            Model.DM_Table_Fields.AddNewItem(Model.Khoa);
        }

        
        void DM_Table_Fields_AddedNew(object sender, Csla.Core.AddedNewEventArgs<DM_Table_FieldChild> e)
        {
            OnChildList_AddedNew(sender, new ChildListAddedNewArgs("DM_Table_Fields"));
        }

       
        protected virtual void OnChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (ChildList_AddedNew != null)
            {
                //Invokes the delegates.
                ChildList_AddedNew(sender, e);
            }
        }

      
       
       
        #endregion

        #region Delete DM_Table Details Item

        public void DeleteDM_Table_FieldItem(int Index)
        {
            Model.DM_Table_Fields.DeleteItem(Index);
        }
        
        #endregion

        
    }
}
